package com.file.controller;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.entity.Collector;
import com.entity.Measuringpoint;
import com.entity.Meter;
import com.entity.Sysdic;
import com.entity.Terminal;
import com.file.entity.FileCollector;
import com.file.entity.FileCustomer;
import com.file.entity.FileMeasuringpoint;
import com.file.entity.FileMeter;
import com.file.entity.FileTerminal;
import com.file.service.CollectorService;
import com.file.service.CustomerService;
import com.file.service.MeasuringpointService;
import com.file.service.MeterService;
import com.file.service.TerminalService;
import com.setting.service.SysdicService;
import com.utils.JsonResult;
import com.utils.JsonSysdic;

/**
 * @Title: MeasuringpointController.java
 * @Package com.controller
 * @author 孙梦楠
 * @date 2017年7月25日 上午9:39:01
 * @version V1.0.0
 */

@RestController
@RequestMapping(value = "/file/measuringpoint")
public class MeasuringpointController {

	@Autowired
	private MeasuringpointService measuringpointservice;

	@Autowired
	private SysdicService sysdicservice;

	@Autowired
	private CollectorService collectorservice;

	@Autowired
	private MeterService meterservice;

	@Autowired
	private TerminalService terminalservice;

	@Autowired
	private CustomerService customerservice;

	// 列出所有符合org的采集器
	@RequestMapping(value = "/listallcollector", method = RequestMethod.GET)
	public JsonResult<List<FileCollector>> listcollector(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return collectorservice.listcollector(opeorgcookie,opetypecookie,languagecookie);
	}

	// 列出所有符合org的集中器
	@RequestMapping(value = "/listallterminal", method = RequestMethod.GET)
	public JsonResult<List<FileTerminal>> listallterminal(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return terminalservice.listTerminal(opeorgcookie,opetypecookie,languagecookie);
	}

	// 列出所有未运行的表
	@RequestMapping(value = "/list_offline_meter", method = RequestMethod.GET)
	public JsonResult<List<FileMeter>> listofflinemeter(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return meterservice.listallmeter(opeorgcookie,opetypecookie, "2", 172, "列出所有未运行表",languagecookie);
	}

	// 列出所有已运行的表
	@RequestMapping(value = "/list_online_meter", method = RequestMethod.GET)
	public JsonResult<List<FileMeter>> listonlinemeter(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return meterservice.listallmeter(opeorgcookie, opetypecookie,"3", 187, "列出所有已运行的表",languagecookie);
	}

	// 列出所有已连接表的用户

	@RequestMapping(value = "/list_install_customer", method = RequestMethod.GET)
	public JsonResult<List<FileCustomer>> listallcustomer(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return customerservice.listallcustomer(opeorgcookie, "2", 188, "列出所有已连接表的用户",languagecookie);
	}

	// // 列表
	// @RequestMapping(value = "", method = RequestMethod.GET)
	// public JsonResult<List<FileMeasuringpoint>> listmeasuringpoint(
	// @CookieValue(value = "opeorgcookie", required = false) String opeorgcookie) {
	//
	// return measuringpointservice.listmeasuringpoint(opeorgcookie);
	// }

	// 条件列表
	@RequestMapping(value = "", method = RequestMethod.POST)
	public JsonResult<List<FileMeasuringpoint>> listmeasuringpointByConditions(

			@RequestBody Measuringpoint measuringpoint,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		Integer terminalid = measuringpoint.getTerminalid();
		Integer meterid = measuringpoint.getMeterid();
		Integer collectorid = measuringpoint.getCollectorid();
		String measuringpointnumber = measuringpoint.getMeasuringpointnumber();
		String measuringpointordernumber = measuringpoint.getMeasuringpointordernumber();
		String measuringpointport = measuringpoint.getMeasuringpointport();
		String measuringpointbaud = measuringpoint.getMeasuringpointbaud();
		String measuringpointbigint = measuringpoint.getMeasuringpointbigint();
		String measuringpointsmallint = measuringpoint.getMeasuringpointsmallint();
		String measuringpointint = measuringpoint.getMeasuringpointint();
		String measuringpointdec = measuringpoint.getMeasuringpointdec();

		return measuringpointservice.listmeasuringpointByConditions(terminalid, meterid, collectorid,
				measuringpointnumber, measuringpointordernumber, measuringpointport, measuringpointbaud,
				measuringpointbigint, measuringpointsmallint, measuringpointint, measuringpointdec, opeorgcookie,opetypecookie,languagecookie);
	}
	//根据终端ID列出所有采集点列表（实际值）
	@RequestMapping(value = "/list_measuringpoint_by_terminalId", method = RequestMethod.POST)
	public JsonResult<List<Measuringpoint>> listMeasuringpointByTerminalId(@RequestBody Terminal ternimal){
		
		Integer terminalid=ternimal.getTerminalid();
		
		return  measuringpointservice.listMeasuringpointByTerminalId(terminalid);
	}

	// 字典
	@RequestMapping(value = "/listsysdicMeasuringpointport", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeasuringpointport(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0012";
		Integer state = 216;
		String Message = "Measuringpointport字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMeasuringpointbaud", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeasuringpointbaud(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0013";
		Integer state = 217;
		String Message = "Measuringpointbaud字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMeasuringpointbigint", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeasuringpointbigint(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0014";
		Integer state = 218;
		String Message = "Measuringpointbigint字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMeasuringpointsmallint", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeasuringpointsmallint(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0015";
		Integer state = 219;
		String Message = "Measuringpointsmallint字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMeasuringpointint", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeasuringpointint(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0016";
		Integer state = 220;
		String Message = "Measuringpointint字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMeasuringpointdec", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeasuringpointdec(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0017";
		Integer state = 221;
		String Message = "Measuringpointdec字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	// 通过ID查到单个数据
	@RequestMapping(value = "/getbyid", method = RequestMethod.POST)
	public JsonResult<FileMeasuringpoint> updateviewmeasuringpointid(@RequestBody Measuringpoint measuringpoint,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {
		Integer measuringpointid = measuringpoint.getMeasuringpointid();
		return measuringpointservice.updateviewmeasuringpoint(measuringpointid,languagecookie);
	}

	// 增加采集点
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public JsonResult<Measuringpoint> addmeasuringpoint(@RequestBody Measuringpoint measuringpoint

	) {
		Integer terminalid = measuringpoint.getTerminalid();
		Integer meterid = measuringpoint.getMeterid();
		Integer collectorid = measuringpoint.getCollectorid();
		String measuringpointnumber = measuringpoint.getMeasuringpointnumber();
		String measuringpointordernumber = measuringpoint.getMeasuringpointordernumber();
		String measuringpointport = measuringpoint.getMeasuringpointport();
		String measuringpointbaud = measuringpoint.getMeasuringpointbaud();
		String measuringpointbigint = measuringpoint.getMeasuringpointbigint();
		String measuringpointsmallint = measuringpoint.getMeasuringpointsmallint();
		String measuringpointint = measuringpoint.getMeasuringpointint();
		String measuringpointdec = measuringpoint.getMeasuringpointdec();

		return measuringpointservice.addmeasuringpoint(terminalid, meterid, collectorid, measuringpointnumber,
				measuringpointordernumber, measuringpointport, measuringpointbaud, measuringpointbigint,
				measuringpointsmallint, measuringpointint, measuringpointdec);
	}

	// 删除采集点
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public JsonResult<Measuringpoint> deletemeasuringpoint(@RequestBody Measuringpoint measuringpoint) {
		Integer measuringpointid = measuringpoint.getMeasuringpointid();

		return measuringpointservice.deletemeasuringpoint(measuringpointid);
	}

	// 修改采集点
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public JsonResult<Measuringpoint> updatemeasuringpoint(@RequestBody Measuringpoint measuringpoint) {

		Integer measuringpointid = measuringpoint.getMeasuringpointid();
		Integer terminalid = measuringpoint.getTerminalid();
		Integer meterid = measuringpoint.getMeterid();
		Integer collectorid = measuringpoint.getCollectorid();
		String measuringpointnumber = measuringpoint.getMeasuringpointnumber();
		String measuringpointordernumber = measuringpoint.getMeasuringpointordernumber();
		String measuringpointport = measuringpoint.getMeasuringpointport();
		String measuringpointbaud = measuringpoint.getMeasuringpointbaud();
		String measuringpointbigint = measuringpoint.getMeasuringpointbigint();
		String measuringpointsmallint = measuringpoint.getMeasuringpointsmallint();
		String measuringpointint = measuringpoint.getMeasuringpointint();
		String measuringpointdec = measuringpoint.getMeasuringpointdec();

		return measuringpointservice.updatemeasuringpoint(measuringpointid, terminalid, meterid, collectorid,
				measuringpointnumber, measuringpointordernumber, measuringpointport, measuringpointbaud,
				measuringpointbigint, measuringpointsmallint, measuringpointint, measuringpointdec);

	}

}
